package com.bckj.freshnow.order.controller;

import com.bckj.freshnow.order.model.CreateTradeOrderRequest;
import com.bckj.freshnow.order.model.CreateTradeOrderResponse;
import com.bckj.freshnow.order.model.TradeOrderRequest;
import com.bckj.freshnow.order.model.TradeOrderResponse;
import com.bckj.freshnow.order.service.TradeOrderService;

import org.springframework.web.bind.annotation.*;

import com.bckj.fastboot.core.page.annotation.PageQuery;
import com.github.pagehelper.PageInfo;

import lombok.RequiredArgsConstructor;
import java.util.List;


/**
 * 交易订单表(TradeOrder)表控制层
 *
 * @author makejava
 * @since 2025-04-22 10:19:40
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("trade")
public class TradeOrderController {
    /**
     * 服务
     */
	private final TradeOrderService tradeOrderService;
	
    /**
	 * 列表
	 *
	 * @param request req
	 * @return list
	 */
	@PageQuery
	@GetMapping("page")
	public PageInfo<TradeOrderResponse> page(TradeOrderRequest request) {
		List<TradeOrderResponse> data = tradeOrderService.findAll(request);
		return new PageInfo<>(data);
	}
	
    /**
	 * 列表
	 *
	 * @param request req
	 * @return list
	 */
	@GetMapping("list")
	public List<TradeOrderResponse> list(TradeOrderRequest request) {
		return tradeOrderService.findAll(request);
	}

	/**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
	@PostMapping
	public boolean save(@RequestBody TradeOrderRequest request) {
		return tradeOrderService.save(request);
	}

	/**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	@PutMapping
	public boolean update(@RequestBody TradeOrderRequest request) {
		return tradeOrderService.update(request);
	}

	/**
	 * 移除
	 *
	 * @param id id
	 * @return boolean
	 */
	@DeleteMapping("{id}")
	public boolean remove(@PathVariable Long id) {
		return tradeOrderService.remove(id);
	}

	/**
	 * 详情
	 *
	 * @param id id
	 * @return response
	 */
	@GetMapping("{id}")
	public TradeOrderResponse details(@PathVariable Long id) {
		return tradeOrderService.details(id);
	}

	/**
	 * 预创建
	 */
	@PostMapping("pre-create")
	public CreateTradeOrderResponse preCreate(@RequestBody CreateTradeOrderRequest request) {
		return tradeOrderService.preCreate(request);
	}


	/**
	 * 计价
	 */
	@PostMapping("pricing")
	public CreateTradeOrderResponse pricing(@RequestBody CreateTradeOrderRequest request) {
		return tradeOrderService.pricing(request);
	}


	/**
	 * 创建
	 */
	@PostMapping("create")
	public CreateTradeOrderResponse create(@RequestBody CreateTradeOrderRequest request) {
		return tradeOrderService.create(request);
	}
}

